package com.olinsports.system.olinsportssystem.service;

import com.olinsports.system.olinsportssystem.model.CommodityDetailed;
import com.olinsports.system.olinsportssystem.model.CommodityType;
import com.olinsports.system.olinsportssystem.repository.CommodityTypeRepository;
import com.olinsports.system.olinsportssystem.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/22.
 */
@Service
public class CommodityTypeService {
    @Autowired
    private CommodityTypeRepository commodityTypeRepository;

    private int totalPages = 0;//总页数

    private int  totalRows;//总数据量
    @Autowired
    private PageUtil pageUtil;

    public List<CommodityType> selectAll(){
        return commodityTypeRepository.selectAll();
    }
    public int insertAll(CommodityType commodityType){
        return commodityTypeRepository.insertAll(commodityType);
    }
    public int deleteByKey(int typeKey){
        return commodityTypeRepository.deleteByKey(typeKey);
    }
    public CommodityType selectByTypeKey(int skuType){
        return commodityTypeRepository.selectByTypeKey(skuType);
    }


    public Map listType(String page, String rows, String sord, String sidx){
        int beg = (Integer.valueOf(page)-1)*Integer.valueOf(rows);
        //查询当前表中的总数据量
        totalRows = commodityTypeRepository.findCount();
        System.out.println("totalRows = "+totalRows);
        //通过分页进行查询当前表中的数据
        List<CommodityType> stmCountList =  commodityTypeRepository.findLimit(sord,sidx,beg,Integer.valueOf(rows));

        Map mapList = pageUtil.paging(rows,page,totalRows);
        mapList.put("rows",stmCountList);//设置行显示的数据
        return mapList;
    }


}
